Page 1 of 4 123 ... LastLast
Results 1 to 10 of 37

Thread: Help with Weapon Swapping

  1. #1
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default Help with Weapon Swapping

    Hi

    This is the weapon swap part im working on for my weapon mod , it works fine when theres only one person on the server ie me
    but as soon as theres more then one , it stops working properly and runs twice.

    It works that when you spawn , you hold down the 'Use' Key for 3 seconds to change from allie sniper ( Springfield) to Axis sniper (Kar98sniper) , but then it should remember what you choose and automatically change it the next time you spawn without needing to hold the 'Use' key again , but if you do it will revert back to normal.

    Its exec from the spawn event , but the weapon limiter part of it works fine and is in the same script, so i know local.player works correctly
    Code:
    ////////////////////////////////////////////////////////////
    ////////////// Weapon Swap Part ///////////////////////////
    
    if (getcvar(pe_weapon_swap) == "1") 
    {
    		if(local.player != NULL && local.player != NIL && isAlive(local.player) && local.player.dmteam != spectator)
    
    				{
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    				
    						local.player weaponcommand dual targetname ("weap" + local.player.entnum )
    						local.player.weapon = $("weap" + local.player.entnum ).model
    						
    						if(local.player.weapon != NIL && local.player.weapon != NULL)
    						
    						{
    				
    							 switch(local.player.weapon)
     								 {
      									 case "models/weapons/springfield.tik":
    									 local.take = "models/weapons/springfield.tik"
    									 local.takename = "Springfield"
    									 local.give = "models/weapons/KAR98sniper.tik"
    									 local.givename = "Kar98Sniper"
    									 break
    									 
    									 case "models/weapons/m1_garand.tik":
    									 local.take = "models/weapons/m1_garand.tik"
    									 local.takename = " M1 Garand"
    									 local.give = "models/weapons/kar98.tik"
    									 local.givename = "Mausar kar98"
    									 break
    									 
       								 }
    							
    					   }
    					
    
    
    wait 1
    
    						
    						if(local.player.weapon == local.take)
    						
    						{
    							if(local.player != NULL && local.player != NIL && isAlive(local.player) && local.player.dmteam != spectator)
    						
    								{
    										
    										if(local.player.swap == "1")
    															
    											{
    											local.player take local.take
    											local.player give local.give
    											local.player iprint (local.takename + " has been swapped for " + local.givename) 1
    											local.player ammo rifle -42
    											local.player use local.give
    											local.player iprint ("Hold 'Use' again to change back") 1
    																			
    											wait 1
    																			
    											if (local.player.useheld==1)
    													{
    														  wait 2
    														  if (local.player.useheld==1)
    																			  
    															{
    																local.player take local.give
    																local.player give local.take
    																local.player ammo rifle -42
    																local.player use local.take
    																local.player.swap = "0"
    															}
    													}
    										}
    						
    													
    						if(local.player.swap != "1")
    															
    								{
    										local.player iprint ("Hold 'Use' for 3 Seconds to change") 1
    																		
    										wait 1
    																		
    											if (local.player.useheld==1)
    													{
    														 wait 2
    														 if (local.player.useheld==1)
    																			  
    															{
    																local.player take local.take
    																local.player give local.give
    																local.player ammo rifle -42
    																local.player iprint (local.takename + " has been swapped for " + local.givename) 1
    																local.player use local.give
    																local.player.swap = "1"
    															}
    													}
    									}
    										
    										
    								}	
    						}
    							
    /////////////////////////////////////////////////////////////
    						
    			}				
    }
    wait 1
    //////--------------------------------------------////////////
    
    
    end
    What part am i doing wrong ????

    is it the local.player.swap = 1 etc stuff

    Again , it works perfectly when im by myself in the server but as soon as someone else spawns , it stuffs up

    Why does it loop through and does it twice , aka the "Hold 'Use' for 3 Seconds to change" message appears twice and it takes your weapon away twice etc

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  2. #2
    Developer
    Join Date
    Jun 2010
    Location
    Hungary
    Posts
    291

    Default

    May you had to post the spawn event script too because it's not clear for me why it doesn't work.

    Instead of this:

    Code:
    local.player weaponcommand dual targetname ("weap" + local.player.entnum )
    local.player.weapon = $("weap" + local.player.entnum ).model
    You can use the new reborn command:

    Code:
    local.weap = local.player getactiveweap 0
    if ( local.weap == NIL || local.weap == NULL )
    end
    
    local.player.weapon = local.weap.model
    No need to use targetnames.

  3. #3
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi

    I tried using the getactive weapon before , and it didnt suit what i needed , it wouldnt work properly.

    Its part of my weapon mod , but executed from the reborn spawn event , everything else works fine in the weapon mod ,

    The problem lies where i tried to get it to remember that you already wanted to swap weapons

    ie the

    local.player.swap = 1

    part , unless its not the right way to 'tag' a player with a setting like that or something ,
    its hard to test myself because it only stops working when theres more then 1 player , so it must be the local.player.swap part of it,
    Last edited by Purple Elephant1au; February 5th, 2013 at 04:24 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  4. #4
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Try this:
    Code:
    spawn local.player:////////////////////////////////////////////////////////////
    ////////////// Weapon Swap Part ///////////////////////////
    
    
        if (getcvar(pe_weapon_swap) == "1") 
        {
            if(local.player && /* !local.player.swapping &&*/ isAlive(local.player) && local.player.dmteam != "spectator")
            {
                //local.player.swapping = 1
                local.player weaponcommand dual targetname ("weap" + local.player.entnum )
                local.player.weapon = $("weap" + local.player.entnum ).model
                
                switch(local.player.weapon)
                {
                    case "models/weapons/springfield.tik":
                        local.take = "models/weapons/springfield.tik"
                        local.takename = "Springfield"
                        local.give = "models/weapons/KAR98sniper.tik"
                        local.givename = "Kar98Sniper"
                    break
                     
                    case "models/weapons/m1_garand.tik":
                        local.take = "models/weapons/m1_garand.tik"
                        local.takename = " M1 Garand"
                        local.give = "models/weapons/kar98.tik"
                        local.givename = "Mausar kar98"
                    break
                    default:
                        end
                }
                
                wait 1    
            
                if(local.player && isAlive(local.player) && local.player.dmteam != "spectator")
                {
                    if(local.player.swap == "1")
                    {
                        local.player take local.take
                        local.player give local.give
                        local.player iprint (local.takename + " has been swapped for " + local.givename) 1
                        local.player ammo rifle -42
                        local.player use local.give
                        local.player iprint ("Hold 'Use' again to change back") 1
    
    
                        local.wait = 3.0
                        while(local.player.useheld) {
                            wait 0.25
                            local.wait -= 0.25
                        }
                        
                        if (local.wait <= 0.0) {
                            local.player take local.give
                            local.player give local.take
                            local.player ammo rifle -42
                            local.player use local.take
                            local.player.swap = "0"
                        }
                    } else {    
                        local.player iprint ("Hold 'Use' for 3 Seconds to change") 1
                        local.wait = 3.0
                        while(local.player.useheld) {
                            wait 0.25
                            local.wait -= 0.25
                        }
                        
                        if (local.wait <= 0.0) {
                            local.player take local.take
                            local.player give local.give
                            local.player ammo rifle -42
                            local.player iprint (local.takename + " has been swapped for " + local.givename) 1
                            local.player use local.give
                            local.player.swap = "1"
                        }
                    }    
                }
            }
            //local.player.swapping = 0
        }
    //////--------------------------------------------////////////
    end
    I haven't had time to thoroughly check why your script runs twice but if the problem still persists with this version,
    uncomment the 3 lines of code I added as comments, that ought to do the trick.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  5. #5
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi

    Thanks For Reply

    All looks good so far , but since there is no one on my server atm , i cant test it properly , since it only stops working when theres more players then just me

    But ill get back to you if it works or not , and ill try the commented out parts if the first doesnt work ,

    Although one thing i noticed with your script , The guns do not change until you let go of the 'use' key , so as the player doesnt no when to let go of it , with my one , as soon as you had held it long enough it would change and you could let go of the 'use' key , just wondering if adding a counter down on the screen for the player would mess with the script at all
    Last edited by Purple Elephant1au; February 5th, 2013 at 05:50 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  6. #6
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    People just got on server, and unfortunatly , it runs it twice with your one aswell , cant restart server yet to try uncommentd out parts

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  7. #7
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Hm, could be problem with the spawn event itself, I haven't tried it myself... Easy way to tell if a script is being run twice:
    Code:
    println "run"
    or in your case:
    Code:
    local.player iprint "run"
    at the very top of your script. You'll be able to check if it runs twice when you're alone as well.

    If you want the while loop to stop after 3 seconds add
    Code:
    && 0.0 < local.wait
    in the condition.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  8. #8
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi

    I dont think its the spawn event repeating twice , other parts of the script only run once , like the actual weapon limiter part only runs once cause it has iprints in it also , and it runs fine and only once ,

    Ill post the entire script up and see if you can make sense of why it repeats itself in this instance


    Below is the main script , everything works , apart from the weapon swapping part, which repeats itself
    Code:
    main:
    
    local.result = registerev "spawn" global/custom/weapons.scr::weapon_limiter
    local.result = registerev "connected" global/custom/weapons.scr::connected
    
    end
    
    connected local.player: 
    
    thread weapon_limiter local.player
    
    end
    
    //////--------------------------------------------////////////
    
    weapon_limiter local.player:
    
    teamswitchdelay .2
    
    wait 0.4
    
    
    //////////////////////////////
    local.notallowed[1] = ""
    local.notallowed[2] = ""
    local.notallowed[3] = ""
    local.notallowed[4] = ""
    local.notallowed[5] = ""
    local.notallowed[6] = ""
    local.notallowed[7] = ""
    local.notallowed[8] = ""
    local.notallowed[9] = ""
    local.notallowed[10] = ""
    local.notallowed[11] = ""
    //////////////////////////////////////////////////////////////
    //////////////////////  Get Cvars ////////////////////////////
    
    if(getcvar(PE_mg) == "0")
    		{
    			local.notallowed[1] = "models/weapons/bar.tik"
    			local.notallowed[2] = "models/weapons/mp44.tik"
    		}
    
    if(getcvar(PE_rocket) == "0")
    		{
    			local.notallowed[3] = "models/weapons/bazooka.tik"
    			local.notallowed[4] = "models/weapons/panzerschreck.tik"
    		}
    
    if(getcvar(PE_shotgun) == "0")
    		{
    			local.notallowed[5] = "models/weapons/shotgun.tik"
    		}
    
    if(getcvar(PE_rifle) == "0")
    		{
    			local.notallowed[6] = "models/weapons/m1_garand.tik"
    			local.notallowed[7] = "models/weapons/kar98.tik"
    		}
    
    if(getcvar(PE_sniper) == "0")
    		{
    			local.notallowed[8] = "models/weapons/springfield.tik"
    			local.notallowed[9] = "models/weapons/KAR98sniper.tik"
    		}
    
    if(getcvar(PE_smg) == "0")
    		{
    			local.notallowed[10] = "models/weapons/thompsonsmg.tik"
    			local.notallowed[11] = "models/weapons/mp40.tik"
    		}
    
    if(getcvar(PE_pistol) == "0")
    		{
    			local.player take "models/weapons/colt45.tik"
    			local.player take "models/weapons/p38.tik"
    		}
    
    if(getcvar(PE_grenade) == "0")
    		{
    			local.player take "models/weapons/m2frag_grenade.tik"
    			local.player take "models/weapons/steilhandgranate.tik"
    		}
    
    
    /////////////////////////////////////////////////////////////
    /////////////////////// Message Part /////////////////////////
    
    local.allowed = "Allowed Weapons:"
        if (getcvar(pe_allweapons) == "1") 
            local.allowed += " All Weapons "
        else
        {
            if (getcvar(pe_pistol) == "1") 
                local.allowed += " Pistol,"
            if (getcvar(pe_rifle) == "1")
                local.allowed += " Rifle,"
            if (getcvar(pe_sniper) == "1") 
                local.allowed += " Sniper,"
            if (getcvar(pe_smg) == "1") 
                local.allowed += " SMG,"
            if (getcvar(pe_mg) == "1") 
                local.allowed += " MG,"
            if (getcvar(pe_grenade) == "1") 
                local.allowed += " Grenades,"
            if (getcvar(pe_shotgun) == "1") 
                local.allowed += " Shotgun,"
            if (getcvar(pe_rocket) == "1") 
                local.allowed += " Rocket,"
    
        }
    
    
    ////////////////////////////////////////////////////////////
    ////////////// Weapon Check Part ///////////////////////////
    
    if(local.player != NULL && local.player != NIL && isAlive(local.player) && local.player.dmteam != spectator)
    
    {
    		local.player weaponcommand dual targetname ("weap" + local.player.entnum )
    		local.player.weapon = $("weap" + local.player.entnum ).model
    		
    		if(local.player.weapon != NIL && local.player.weapon != NULL)
    		
    		{
    				for (local.i = 1; local.i <= local.notallowed.size; local.i++) 
    				{
    					   if(local.player.weapon == local.notallowed[local.i])
    						{	
    								local.player take local.notallowed[local.i]
    								if(getcvar(pe_weapon_choice) != "1")
    								{ 
    								local.player give models/weapons/KAR98sniper.tik
    								local.player use models/weapons/KAR98sniper.tik
    								}
    								if(getcvar(pe_weapon_choice) == "1")
    								{
    								local.player spectator
    								local.player stufftext "pushmenu SelectPrimaryWeapon"
    								}
    								if(getcvar(pe_weapon_message) == "1") 
    												{
    													local.player iprint ("The Weapon you chose is unavailable") 1
    													local.player iprint (local.allowed) 1
    													//local.player iprint ("So here is a Sniper") 1	
    												}
    								
    								
    						}		
    					 
    					  if(local.I == game.aAllowedWeapons.size)
    						{
    						break
    						}
    						
    				}
    		}
    }
    
    
    
    
    ////////////////////////////////////////////////////////////
    ////////////// Weapon Swap Part ///////////////////////////
    
    
    
    
        if (getcvar(pe_weapon_swap) == "1") 
        {
            if(local.player && /* !local.player.swapping &&*/ isAlive(local.player) && local.player.dmteam != "spectator")
            {
                //local.player.swapping = 1
                local.player weaponcommand dual targetname ("weap" + local.player.entnum )
                local.player.weapon = $("weap" + local.player.entnum ).model
                
                switch(local.player.weapon)
                {
                    case "models/weapons/springfield.tik":
                        local.take = "models/weapons/springfield.tik"
                        local.takename = "Springfield"
                        local.give = "models/weapons/KAR98sniper.tik"
                        local.givename = "Kar98Sniper"
                    break
                     
                    case "models/weapons/m1_garand.tik":
                        local.take = "models/weapons/m1_garand.tik"
                        local.takename = " M1 Garand"
                        local.give = "models/weapons/kar98.tik"
                        local.givename = "Mausar kar98"
                    break
                    default:
                        end
                }
                
                wait 1    
            
                if(local.player && isAlive(local.player) && local.player.dmteam != "spectator")
                {
                    if(local.player.swap == "1")
                    {
                        local.player take local.take
                        local.player give local.give
                        local.player iprint (local.takename + " has been swapped for " + local.givename) 1
                        local.player ammo rifle -42
                        local.player use local.give
                        local.player iprint ("Hold 'Use' again to change back") 1
    
    
                        local.wait = 3.0
                        while(local.player.useheld) {
                            wait 0.25
                            local.wait -= 0.25
                        }
                        
                        if (local.wait <= 0.0) {
                            local.player take local.give
                            local.player give local.take
                            local.player ammo rifle -42
                            local.player use local.take
                            local.player.swap = "0"
                        }
                    } else {    
                        local.player iprint ("Hold 'Use' for 3 Seconds to change") 1
                        local.wait = 2.0
                        while(local.player.useheld) {
                            wait 0.25
                            local.wait -= 0.25
                        }
                        
                        if (local.wait <= 0.0) {
                            local.player take local.take
                            local.player give local.give
                            local.player ammo rifle -42
                            local.player iprint (local.takename + " has been swapped for " + local.givename) 1
                            local.player use local.give
                            local.player.swap = "1"
                        }
                    }    
                }
            }
            //local.player.swapping = 0
        }
    //////--------------------------------------------////////////
    end
    //////--------------------------------------------////////////

    Anyways its late atm for me so ill get back to it tomorrow night

    Thanks for your help
    Last edited by Purple Elephant1au; February 7th, 2013 at 12:22 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  9. #9
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi

    Ok i got it to stop repeating as much , but still doesnt work when the round starts , works when players are on same team but not when round starts

    I think it must be something to do with the spawn event not liking Freezetag much , like when i added a iprint into the start of the script , it showed that the script also runs when the player is in the freezetag spectate mode , ie following the player still alive or the frozen bodies , i had this problem awhile ago and thought it just might be the mod i was using but know i think its the spawn event not likeing freezetag

    Any1 else have this problem who is running a spawn event and ftag?

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  10. #10
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    The possibilities:
    1. The registerev() call was made before level waittill spawn. When a round restarts,
    the mapscript will be run again but starting from level waittill spawn (the execution of the dmprecache is also before this).
    2. Mefy simulates round restarts, he actually forces the respawn event on all players. I don't think such a spawn is detected
    by Reborn's spawn event much like it doesn't detect the respawns when an admin forces the server to restart. Too bad, really,
    I'm implementing a custom spawn event logic for the framework but I would've used the reborn spawn event if it were 100%
    accurate.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

Page 1 of 4 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •